#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NMAX 500000

/*
 * 'static' breaks merge sort :(
 */

struct unit {
	int value;
	char name[10];
};


static struct unit sorted[NMAX];


static void
Merge_sort__merge(struct unit *array, int L, int M, int R)
{
	register int i = L,
		     j = M+1,
		     s = 0; /* index. points to where we will place next element */

	while (i <= M && j <= R) {
		if (array[i].value <= array[j].value)
			sorted[s++] = array[i++];
		else
			sorted[s++] = array[j++];
	}
	while (i <= M)
		sorted[s++] = array[i++];
	while (j <= R)
		sorted[s++] = array[j++];

	i = 0;
	while (i < s) {
		array[L + i] = sorted[i];
		++i;
	}
}



static void
Merge_sort__main(struct unit *array, int L, int R)
{
	int M;
	if (L < R) {
		M = (L + R) / 2;

		Merge_sort__main(array, L, M);
		Merge_sort__main(array, M+1, R);

		Merge_sort__merge(array, L, M, R);
	}
}



void
Merge_sort_(struct unit *array, int size)
{
	return Merge_sort__main(array, 0, size-1);
}



static int
sum_digits_dec(const char * s, int length)
{
	const int pow = 10;
	int answer = 0;
	while (*s != '\0') {
		if (*s >= '0' && *s <= '9') {
			/* answer *= pow; //lol stupid */
			answer += *s - '0';
		} /* lol */
		++s;
	}
	return answer;
}



int
main(void)
{
	struct unit array[NMAX];
	int n;
	register int i = 0;

	(void) freopen("stable.in", "r", stdin);
	(void) freopen("stable.out", "w", stdout);

	(void) scanf("%d", &n);
	while (i < n) {
		(void) scanf("%s", array[i].name);
		array[i].value = sum_digits_dec(array[i].name, (int)strlen(array[i].name));
		++i;
	}

	Merge_sort_(array, n);

	for (i = 0 ; i < n ; ++i)
		(void) printf("%s ", array[i].name);
	putchar('\n');
	return 0;
}
